package com.daoxuehao.baseframework.module.main;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.daoxuehao.baseframework.R;
import com.daoxuehao.baseframework.app.BaseActivity;
import com.daoxuehao.baseframework.model.api.ApiManager;
import com.daoxuehao.baseframework.model.beans.IpInfo;
import com.daoxuehao.baseframework.module.IPresenter;
import com.daoxuehao.baseframework.module.main.presenter.MainPresenter;
import com.daoxuehao.baseframework.module.main.view.IMainView;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity implements IMainView {

    @Bind(R.id.text)
    TextView text;
    @Bind(R.id.mProgressBar)
    ProgressBar mProgressBar;

    private MainPresenter mMainPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();
    }


    @Override
    protected IPresenter initPresenter() {
        mMainPresenter = new MainPresenter(this);
        return mMainPresenter;
    }

    private void initView() {
        text = (TextView) findViewById(R.id.text);
        mProgressBar = (ProgressBar) findViewById(R.id.mProgressBar);


        initPresenter();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mMainPresenter.loadData();
            }
        }, 2000);

    }
    @Override
    public void showData(IpInfo mainModelBean) {
       // String showData = getResources().getString(R.string.city) + mainModelBean.getCity()
       //         + getResources().getString(R.string.wd) + mainModelBean.getWd()
       //         + getResources().getString(R.string.ws) + mainModelBean.getWs()
       //         + getResources().getString(R.string.time) + mainModelBean.getTime();
        text.setText(mainModelBean.country);
    }

    @Override
    public void showProgress() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        mProgressBar.setVisibility(View.GONE);
    }
}
